<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!doctype html>
<html>
<head>
		<!-- Basic Page Needs -->
        <meta charset="utf-8">
        <title>选座</title>
        <meta name="description" content="A Template by Gozha.net">
        <meta name="keywords" content="HTML, CSS, JavaScript">
        <meta name="author" content="Gozha.net">
    <!-- Mobile Specific Metas-->  
    	<meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta content="telephone=no" name="format-detection">
    <!-- Fonts -->
        <!-- Font awesome - icon font -->
        <link href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
        <!-- Roboto -->
        <link href='http://fonts.useso.com/css?family=Roboto:400,700' rel='stylesheet' type='text/css'>
    	<!-- Stylesheets -->
		<!--后加的 选座-->
	 <link rel="stylesheet" type="text/css" href="css/seat-charts.css" /> 
        <!-- Mobile menu -->
        <link href="css/gozha-nav.css" rel="stylesheet" />
        <!-- Select -->
        <link href="css/external/jquery.selectbox.css" rel="stylesheet" />
        <link href="css/style-before.css?v=1" rel="stylesheet" />
        <!-- Custom -->
        <link href="css/style.css?v=1" rel="stylesheet" />
        <!-- Modernizr --> 
        <script src="js/external/modernizr.custom.js"></script>

        <script type="text/javascript" src="js/jquerysession.js"></script>
    
</head>

<body>
    <div class="wrapper">
        <!-- Banner -->
        <jsp:include page="header.jsp"></jsp:include>
        
        <input type="hidden" value="<%=request.getParameter("seat") %>" id="seat">
        
        <!-- Main content -->
        <section class="container">
            <div class="order-container">
                <div class="order">
                    <img class="order__images" alt='' src="images/tickets.png">
                    <p class="order__title">购买电影票 <br><span class="order__descript">祝您观影愉快</span></p>
                    <div class="order__control">
                        <a href="" class="order__control-btn active">购买</a>
                      
                    </div>
                </div>
            </div>
                <div class="order-step-area">
                  
                    <div class="order-step second--step order-step--disable">1.选座</div>
                    <div class="order-step third--step">2. 支付</div>
                </div>

            <div class="col-sm-12">
                <div class="checkout-wrapper">
                    <h2 class="page-heading">价格</h2>
                    <ul class="book-result">
                        <li class="book-result__item">座位: <span class="book-result__count booking-ticket" id="num"></span></li>
                        <li class="book-result__item">单价: <span class="book-result__count booking-price" id="price">￥<%=request.getParameter("price")%></span></li>
                        <li class="book-result__item">折扣: <span class="book-result__count booking-price" id="discountLevel"></span></li>
                        <li class="book-result__item">折后： <span class="book-result__count booking-cost" id="afterdiscount"></span>
                        <span class="" style="text-decoration:line-through;color:#D3D3D3;font-size:15px" id="total_price">￥<%=request.getParameter("total_price")%></span></li>
                    </ul>

                    <h2 class="page-heading">选择支付方式</h2>
                    <div class="payment">
                        <a href="#" class="payment__item">
                            <img alt='' src="themovieimg/支付宝.jpg" width="100px" height="60px">
                        </a>
                    </div>
                </div>
                
                <div class="order">
                    <a href="#" class="btn btn-md btn--warning btn--wide" id="pay">支付</a>
                </div>

            </div>

        </section>
        

        <div class="clearfix"></div>

         <div class="booking-pagination booking-pagination--margin">
                <a href="SelectSeat.jsp?movieid=<%=request.getParameter("movieid")%>&scheduleid=<%=request.getParameter("scheduleid")%>" class="booking-pagination__prev">
                    <span class="arrow__text arrow--prev">上一步</span>
                    <span class="arrow__info">选座位</span>
                </a>
          </div>
        
        <div class="clearfix"></div>
        <jsp:include page="footer.jsp"></jsp:include>

       
    </div>
    
    <jsp:include page="LoginAndRegister.jsp"></jsp:include>


	<!-- JavaScript-->
        <!-- jQuery 1.9.1--> 
        <script src="http://ajax.useso.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
        <script>window.jQuery || document.write('<script src="js/external/jquery-1.10.1.min.js"><\/script>')</script>
        <!-- Migrate --> 
        <script src="js/external/jquery-migrate-1.2.1.min.js"></script>
        <!-- Bootstrap 3--> 
        <script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script>
		<!-- jQuery REVOLUTION Slider -->
		<script type="text/javascript" src="rs-plugin/js/jquery.themepunch.plugins.min.js"></script>
		<script type="text/javascript" src="rs-plugin/js/jquery.themepunch.revolution.min.js"></script>
        <!-- Mobile menu -->
        <script src="js/jquery.mobile.menu.js"></script>
         <!-- Select -->
        <script src="js/external/jquery.selectbox-0.2.min.js"></script>

        <!-- Form element -->
        <script src="js/external/form-element.js"></script>
        <!-- Form validation -->
        <script src="js/form.js"></script>
		<script src="js/custom.js"></script>
        <!-- Custom -->
        <script src="js/customf.js"></script>
        
        <script type="text/javascript">
	    //自动生成订单号
	    function GetDateNow() {
		var vNow = new Date();
		var sNow = "";

		sNow += String(vNow.getMinutes());
		sNow += String(vNow.getSeconds());
		sNow += String(vNow.getMilliseconds());
		return sNow;
	    }	
        </script>
		<script type="text/javascript">
		    $(document).ready(function() {
		      init_Home();
		    });
		</script>
		<script type="text/javascript">
		var movieid=<%=request.getParameter("movieid")%>;
		var scheduleid=<%=request.getParameter("scheduleid")%>;
		var price=<%=request.getParameter("price")%>;
		var total_price=<%=request.getParameter("total_price")%>;
		var userid=<%=session.getAttribute("userid")%>;
		var seat=[<%=request.getParameter("seat")%>];
		var num=seat.length;
		var orderprice;
		
		var seat1=$("#seat").val();
		
		$("#num").text(num);
		
		//获取折扣并赋值
		$.ajax({
		   url:"getDiscountLevel",
		   type:"get",
		   data:{
			   userid:userid
		   },
		   dataType:"json",
		   success:function(data){
			   console.log(data);
			   $("#discountLevel").text(data.discountlevel*10);
			   $("#afterdiscount").text("￥"+data.discountlevel*price*num);
			   orderprice=data.discountlevel*price*num*1.0;
		   }
		});
		
		//点击支付--添加订单
		$("#pay").click(function(){
			var orderid=parseInt(GetDateNow());
			var orders={
					orderid:orderid,
					users:{
						userid:userid
					},
					schedule:{
						scheduleid:scheduleid
					},
					orderprice:orderprice,
					seat:seat1
			};
			
			$.ajax({
				url:"addOrderss",
				type:"post",
				data:JSON.stringify(orders),
				dataType:"json",
				contentType:"application/json",
				success:function(data){
					if(data.code==1){
						console.log(data.msg);
						//跳转到支付页面
						location.href = "http://localhost:8080/My_Popcorn/alipaySum?out_trade_no="+orderid+"&total_amount="+orderprice+"&cus="+orderid+"&scheduleid="+scheduleid;
					}
				}				
			});	
		});
	</script>
	
	<jsp:include page="JudegeLogin.jsp"></jsp:include>

</body>
</html>
